import React, { lazy, Suspense } from 'react'
import ReactDOM from 'react-dom/client'
import { BrowserRouter, Route, Routes,HashRouter } from 'react-router-dom'
import { Loading, Space } from 'react-vant'
import PcTipPage from './PcTipPage'
import './index.css'

const AppPage = lazy(() => import('./App'))
const HomePage = lazy(() => import('./views/Home/Index'))
const PushNotePage = lazy(() => import('./views/PushNote/Index'))
const MyPage = lazy(() => import('./views/My/Index'))
const FeedBack = lazy(() => import('./views/FeedBack/Index'))
const VipNoteList = lazy(() => import('./views/VipNoteList/Index'))
const Records = lazy(() => import('./views/My/Records/Index'))
const Share = lazy(() => import('./views/My/Share/Index'))

const loadingComponent = () => {
    return (
        <Space justify='center' align='center' block style={{ height: '100%' }}>
            <Loading type='ball' />
        </Space>
    )
}

// 判断页面只能在移动端打开
if (!window.navigator.userAgent.includes('Mobile')) {
    ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
        <PcTipPage />
    )
} else {
    ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
        // <React.StrictMode>
        <Suspense fallback={loadingComponent()}>
            <BrowserRouter>
                <Routes>
                    <Route element={<AppPage />}>
                        <Route index element={<HomePage />}></Route>
                        <Route path='/pushNote' element={<PushNotePage />}></Route>
                        <Route path='/my' element={<MyPage />}></Route>
                        <Route path='/feedback' element={<FeedBack />}></Route>
                        <Route path='/vipNoteList' element={<VipNoteList />}></Route>
                        <Route path='/records' element={<Records />}></Route>
                        <Route path='/share' element={<Share />}></Route>
                    </Route>
                </Routes>
            </BrowserRouter>
        </Suspense>
        // </React.StrictMode>
    )
}